/*
 * Copyright (c) 2017, Li Bo/Alex Lee All rights reserved.
 * 
 * http://www.libo4dream.club/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.hyts.socketio.base;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.DataListener;
import com.hyts.socketio.config.BaseServerConfig;

/**
 * @ClassName: BaseSocketIOListener
 * @Description: 基础BaseSocketIO服务监听器
 * @author: LiBo/Alex Lee
 * @date: 2017年10月7日 下午2:04:04
 * @email: alexlibochn@china-pui.com.cn/alex.link@foxmail.com
 */
public class BaseSocketIOListener implements DataListener<BaseSocketIOModel> {

	/**
	 * @fieldName: socketIOServer
	 * @fieldType: SocketIOServer
	 * @Description:SocketIO服务对象
	 */
	private SocketIOServer socketIOServer;
	
	/**
	 * @Title:BaseSocketIOListener
	 * @Description:TODO
	 * @param socketIOServer
	 */
	public BaseSocketIOListener(SocketIOServer socketIOServer) {
		super();
		this.socketIOServer = socketIOServer;
	}


	/* (non Javadoc)
	 * @Title: onData
	 * @Description: 进行操作程序服务信息
	 * @param client
	 * @param data
	 * @param ackSender
	 * @throws Exception
	 * @see com.corundumstudio.socketio.listener.DataListener#onData(com.corundumstudio.socketio.SocketIOClient, java.lang.Object, com.corundumstudio.socketio.AckRequest)
	 */
	@Override
	public void onData(SocketIOClient client, BaseSocketIOModel data, AckRequest ackSender)
			throws Exception {
		if(socketIOServer != null)
		{
			socketIOServer.getBroadcastOperations().sendEvent(BaseServerConfig.DEFAULT_EVENT_LISTENER_NAME, data);
		}
		else
		{
			throw new RuntimeException("进行构建socket服务数据失败!");
		}
	}

}
